// PDMSPerObjManager.h: interface for the PDMSPerObjManager class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_PDMSPEROBJMANAGER_H__936385F8_B0BE_441F_8BB6_90A5C39069B3__INCLUDED_)
#define AFX_PDMSPEROBJMANAGER_H__936385F8_B0BE_441F_8BB6_90A5C39069B3__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "Tree.h"
#include "Hash.h"
#include "UeObjectId.h"
#include "Configration.h"
#include "PersisterFacade.h"

namespace PDMS
{
	namespace PDMSDBIF
	{
		class PersisterFacadeImp;
	}
	namespace PDMSFrame
	{
		class DllExport PDMSPerObjManager  
		{
			friend class DBManager;
			friend class Hash;
			friend class PDMSDBIF::PersisterFacadeImp;
			
		public:
			PDMSPerObjManager();
			virtual ~PDMSPerObjManager();
			
		public:
			typedef Hash::IteratorPtr IteratorPtr;
		public:
			UESoft::ErrorStatus TreeModel( UeDbObject*& pTree, UeDb::OpenModel om = UeDb::eForWrite );
			UESoft::ErrorStatus GetObject( const UeObjectId& id, UeDbObject*& pTree,
				UeDb::OpenModel om = UeDb::eForWrite );
			IteratorPtr GetObject( const StdString& id );
			Hash* HashModel();
			void RemoveAll();
			UeObjectId GenerateId();
			UESoft::ErrorStatus Save();
			
		public:
			ModelType GetModelType() const {
				return m_eType;
			}

			const StdString& Name() const {
				return m_strName;
			}
			
			const UeObjectId& WorldId() const {
				return m_WorldId;
			}

		protected:
			void SetModelType( ModelType eType ) {
				m_eType = eType;
			}
			
			void Name( const StdString& strName ) {
				if ( strName.IsEmpty() )
					return;
				m_strName = strName;
			}

			UESoft::ErrorStatus Create();
			
			void SetEnvID( unsigned long lEnvID ) {
				m_lEnvID = lEnvID;
			}

			unsigned long GetEnvID() const {
				return m_lEnvID;
			}
			
			void SetMaxElementID( unsigned long lID ) {
				m_lMaxElementID = lID;
			}

			unsigned long GetMaxElementID() {
				if ( m_pIDGen != NULL )
					m_lMaxElementID = m_pIDGen->CurCount();
				return m_lMaxElementID;
			}

			const PersisterFacadePtr& GetPersisterFacade() const {
				return m_PFPtr;
			}
			
			void WorldId( const UeObjectId& id ) {
				m_WorldId = id;
			}
		private:
			ModelType m_eType;
			Hash m_hash;
			IDGenerator* m_pIDGen;
			StdString m_strName;
			UeObjectId m_WorldId;
			PersisterFacadePtr m_PFPtr;
			unsigned long m_lEnvID;
			unsigned long m_lMaxElementID;
		};
	}
}

#endif // !defined(AFX_PDMSPEROBJMANAGER_H__936385F8_B0BE_441F_8BB6_90A5C39069B3__INCLUDED_)
